﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Threading;
using System.Collections.ObjectModel;

namespace gui {

    /// <summary>
    /// GUI Notifiable ChartInfo Class
    /// Contains a title, description and an observable collection of lgorithmItems
    /// </summary>
    public class ChartInfo : DependencyObject {

        public static ChartInfo Instance;
        public static Dispatcher _Dispatcher { get; set; }

        public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(ChartInfo));
        public static DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(ChartInfo));
        public static DependencyProperty AlgorithmsListProperty = DependencyProperty.Register("AlgorithmsList", typeof(ObservableCollection<AlgorithmItem>), typeof(ChartInfo));

        static ChartInfo() {
            Instance = new ChartInfo();
        }

        public string Title {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }
        public string Description {
            get { return (string)GetValue(DescriptionProperty); }
            set { SetValue(DescriptionProperty, value); }
        }
        public ObservableCollection<AlgorithmItem> AlgorithmsList {
            get { return (ObservableCollection<AlgorithmItem>)GetValue(AlgorithmsListProperty); }
            set { SetValue(AlgorithmsListProperty, value); }
        }

        public static void SetChart(string title, string desc) {
            if (title.Equals(null) || desc.Equals(null))
                Default();

            if (_Dispatcher != null) {
                _Dispatcher.BeginInvoke(
                    DispatcherPriority.Send,
                    new Action(delegate() {
                    Instance.Title = "Algorithm Chart :: " + title;
                    Instance.Description = desc;
                }));
            }
        }

        public static void Default() {
            if (_Dispatcher != null) {
                _Dispatcher.BeginInvoke(
                     DispatcherPriority.Send,
                    new Action(delegate() {
                        Instance.Title = "Algorithm Chart";
                        Instance.Description = "Please select an algorithm to view from the algorithms list below. Note: In order to utilise this form of output, the algorithm must implement a chartRenderer.";
                    }));
            }
        }

    }
}
